﻿using MediatR;
using Return.Enum;
using SlaughterItem.Common.Infrastructures.Interfaces;
using THE_WIND_RISES.Common.Domans.BasicInformation.MainPlans;
using THE_WIND_RISES.Common.Dtos;

namespace Enterprise_Set.API.Application.Commands.Week2.Mainplan_CRUD
{
    /// <summary>
    /// 修改主生产任务明细表
    /// </summary>
    public class UpMainplandetailHandler : IRequestHandler<UpMainplandetailCommand, Result>
    {
        public UpMainplandetailHandler(IBaseRepository<Mainplandetail> mainplandetailRepository)
        {
            MainplandetailRepository = mainplandetailRepository;
        }

        public IBaseRepository<Mainplandetail> MainplandetailRepository { get; set; }
        public async Task<Result> Handle(UpMainplandetailCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCodes.Update };
            var sql = "update mainplandetails set SuppliesData=@SuppliesData,SuppliesNature=@SuppliesNature,BomVersions=@BomVersions,MainplandetailNum=@MainplandetailNum,CreateTime=@CreateTime,FinishTime=@FinishTime,Remark=@Remark,ItemCode=@ItemCode where MainplandetailId=@MainplandetailId";
            var UpNum = MainplandetailRepository.Update(sql, new
            {
                MainplandetailId = request.MainplandetailId,
                ItemCode=request.ItemCode,
                SuppliesData = request.SuppliesData,
                SuppliesNature = request.SuppliesNature,
                BomVersions = request.BomVersions,
                MainplandetailNum = request.MainplandetailNum,
                CreateTime = request.CreateTime,
                FinishTime = request.FinishTime,
                Remark = request.Remark,
            });
            if (UpNum > 0)
            {
                result.Code = (int)CommonErrorCodes.Success;
                return result;
            }
            else
            {
                return result;
            }
        }
    }
}
